package com.gp.dal.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

/**
 * Created by Zhanggd on 2017/7/2.
 */
public class MybatisUtil {

    private static SqlSessionFactory sqlMapper;
    private static InputStream in;

    static {
        try {
            String path = "mybatisConfig.xml";
            in = Resources.getResourceAsStream(path);
            sqlMapper = new SqlSessionFactoryBuilder().build(in);
        } catch (Exception e) {
            System.out.println("没有找到配置文件！");
            e.printStackTrace();
        }
    }

    public static SqlSessionFactory getInstance() {
        return sqlMapper;
    }
}
